using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;

namespace SuperService
{
	partial class Logger : ServiceBase
	{
		public Logger()
		{
			InitializeComponent();
		}

		void timer1_Tick(object sender, EventArgs e)
		{
			LogEvent("This Timer has been ticked!", EventLogEntryType.Information);
		}

		protected override void OnStart(string[] args)
		{
			timer1.Tick += new EventHandler(timer1_Tick);
			timer1.Start();
			LogEvent("This SuperService has started!", EventLogEntryType.Information);
		}

		protected override void OnStop()
		{
			LogEvent("This SuperService has stopped.", EventLogEntryType.Information);
		}

		protected override void OnPause()
		{
			base.OnPause();
			timer1.Stop();
		}

		protected override void OnContinue()
		{
			base.OnContinue();
			timer1.Start();
		}

		static void LogEvent(String Message, EventLogEntryType type)
		{
			String source = "Logger";
			String log = "Application";
			if (!EventLog.SourceExists(source))
			{
				EventLog.CreateEventSource(source, log);
			}

			EventLog eLog = new EventLog();
			eLog.Source = source;

			eLog.WriteEntry(Message, type);
		}
	}
}
